package com.wz.jiangsu.config;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "spring.elasticsearch.rest")
public class ElasticSearchConfig {

    private String uris;


    @Bean
    public RestHighLevelClient client() {
        String[] split = uris.split(":");
        log.info("es连接ip：{}，端口：{}", split[0], split[1]);
        //基本的连接
        RestClientBuilder clientBuilder = RestClient.builder(new HttpHost(split[0], Integer.valueOf(split[1])));
        return new RestHighLevelClient(clientBuilder);
    }
}